<script>
/* eslint-disable */
import Form from '@cci/cp-form'
const components = {
  // SelectTime: () => import("@/component/Select/SelectTime"),
  // SelectCode: () => import("@/component/Select/SelectCode"),
  // SelectConfig: () => import("@/component/Select/SelectConfig"),
  SelectTree: () => import('@/component/Select/SelectTree'),
}
const componentList = Object.keys(components)
const selectRender = function (h, item, opts) {
  return [
    h('c-select', opts, [
      this._l(
        typeof item.xStore === 'function' ? item.xStore() : item.xStore,
        (store) => {
          return h('c-option', {
            props: {
              label: store.label,
              value: store.value,
              disabled: store.disabled,
            },
          })
        }
      ),
    ]),
  ]
}
export default {
  mixins: [Form],
  components,
  beforeCreate () {
    this.R = this.R || {}
    this.R.selectRender = selectRender
    componentList.forEach((name) => {
      this.R[`${name}Render`] = function (h, item, opts) {
        if (!item.anchor) {
          item.anchor = {
            span: 8,
            lg: 12,
            sm: 12,
          }
        }
        // console.log(item.anchor);
        opts.on['change'] = this.mixinEvent(
          opts.on['change'],
          this.handleChange.bind(this, item)
        )
        return [h(name, opts)]
      }
    })
  },
  methods: {
    handleChange (item, e) {
      this.model[item.prop] = e
      this.emitRelated(e, item.relatedFields, item.ref || item.prop)
    },
  },
}
</script>
